package zry.Operate;

import zry.Search.*;
import zry.Achievement.*;
import zry.Achievement.Other.*;
import zry.Achievement.Patent.*;
import zry.Achievement.Platform.*;
import zry.Achievement.Report.*;
import zry.Achievement.Reward.*;
import zry.Achievement.Standard.*;
import zry.Achievement.Textbook.*;
import zry.Achievement.Thesis.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Delete {
    public void deleteApplyAchievement(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        SearchCriteriaAchievement searchCriteriaAchievement = new SearchCriteriaAchievement();
        searchCriteriaAchievement.setS_id(userid);
        List<Achievement> achievements = achievementDAO.findAchievements(searchCriteriaAchievement);

        //去掉已经在审核中的申请
        achievements.removeIf(a -> !a.getP_review().equals(0));

        System.out.println("成果id\t\t成果类型\t\t用户id\t\t初审结果\t\t终审结果");
        System.out.println(" " + achievements.toString().replaceAll("\\[", "").replaceAll(",", "").replaceAll("]", ""));

        //将本人的成果认定申请id存入一个list，用户只能删除本人的未经过审核的申请
        List<String> achievementIds = new ArrayList<>();
        for (Achievement a : achievements) {
            achievementIds.add(a.getA_id());
        }

        System.out.println("——————————————————————\n" +
                "请输入要删除的成果id");
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String input = scanner.nextLine();
            //只有输入的成果id在本人的list中，才能正确显示
            if (achievementIds.contains(input)) {
                Achievement achievement = achievementDAO.getAchievement(input);
                System.out.println("成果id\t\t成果类型\t\t用户id\t\t初审结果\t\t终审结果");
                System.out.println(achievement);
                switch (achievement.getA_type()) {
                    case "论文":
                        ThesisDAO thesisDAO = new ThesisDAOImpl();
                        Thesis thesis = thesisDAO.getThesis(input);
                        System.out.println(thesis);
                        break;
                    case "教材":
                        TextbookDAO textbookDAO = new TextbookDAOImpl();
                        Textbook textbook = textbookDAO.getTextbook(input);
                        System.out.println(textbook);
                        break;
                    case "标准":
                        StandardDAO standardDAO = new StandardDAOImpl();
                        Standard standard = standardDAO.getStandard(input);
                        System.out.println(standard);
                        break;
                    case "奖励":
                        RewardDAO rewardDAO = new RewardDAOImpl();
                        Reward reward = rewardDAO.getReward(input);
                        System.out.println(reward);
                        break;
                    case "报告":
                        ReportDAO reportDAO = new ReportDAOImpl();
                        Report report = reportDAO.getReport(input);
                        System.out.println(report);
                        break;
                    case "平台":
                        PlatformDAO platformDAO = new PlatformDAOImpl();
                        Platform platform = platformDAO.getPlatform(input);
                        System.out.println(platform);
                        break;
                    case "专利":
                        PatentDAO patentDAO = new PatentDAOImpl();
                        Patent patent = patentDAO.getPatent(input);
                        System.out.println(patent);
                        break;
                    case "其他":
                        OtherDAO otherDAO = new OtherDAOImpl();
                        Other other = otherDAO.getOther(input);
                        System.out.println(other);
                        break;
                }
                System.out.println("是否确认删除（y/n）");
                if (scanner.nextLine().equals("y")) {
                    achievementDAO.deleteAchievement(input);
                    System.out.println("删除提交成功");
                }
                break;
            } else {
                System.out.println("成果id输入错误，请输入本人的成果id");
            }
        }
    }
}
